<?php

namespace Part14_ObserverMode\Code3;

class Boss implements Subject
{
    private $observers;
    private $action;

    public function attach($observer)
    {
        $this->observers[] = $observer;
    }

    public function detach($observer)
    {
        if (in_array($observer, $this->observers)) {
            unset($this->observers[array_search($observer, $this->observers)]);
        }
    }

    public function notify()
    {
        foreach ($this->observers as $observer) {
            $observer->update();
        }
    }

    public function setAction($action)
    {
        $this->action = $action;
    }

    public function getAction()
    {
        return '老板发出通知：' . $this->action;
    }
}